import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue2";
import path from "path";
import { fileURLToPath, URL } from "node:url";
import cdn from "vite-plugin-cdn-import";
import createDemoCodeFilePlugin from './build/vitePlugin/createDemoCodeFilePlugin'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    createDemoCodeFilePlugin(),
    cdn({
      enableInDevMode: true,
      modules: [
        {
          name: "vue",
          var: "Vue",
          path: `https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js`,
        },
        {
          name: "vue-router",
          var: "VueRouter",
          path: `https://cdn.jsdelivr.net/npm/vue-router@3.5.2/dist/vue-router.min.js`,
        },
        {
          name: "element-ui",
          var: "ELEMENT",
          path: `https://cdn.jsdelivr.net/npm/element-ui@2.15.14/lib/index.min.js`,
          css: "https://cdn.jsdelivr.net/npm/element-ui@2.15.14/lib/theme-chalk/index.min.css",
        },
        {
          name: "xe-utils",
          var: "XEUtils",
          path: `https://cdn.jsdelivr.net/npm/xe-utils@3.5.26/dist/xe-utils.umd.min.js`,
        },
        {
          name: "vxe-table",
          var: "VXETable",
          path: `https://cdn.jsdelivr.net/npm/vxe-table@3.8.6/lib/index.umd.min.js`,
          css: "https://cdn.jsdelivr.net/npm/vxe-table@3.8.6/lib/style.min.css",
        },
        {
          name:"remarkable",
          var:"remarkable",
          path:"https://unpkg.com/remarkable@latest/dist/remarkable.min.js"
        }
      ],
    }),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
      "@qqt/sdk": fileURLToPath(new URL("./packages", import.meta.url)),
    },
  },

  build: {
    lib: {
      entry: path.resolve(__dirname, "packages/index.js"),
      name: "qqtsdk",
      fileName: (format) => `qqtsdk.${format}.js`,
    },
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ["vue"],
      output: {
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: {
          vue: "Vue",
        },
      },
    },
  },
});
